﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using Be;

namespace Bll {

    /// <summary>
    /// The service class for lessons which implements
    /// the ILessonService interface
    /// </summary>
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class BllLessonService : ILessonService {

        /// <summary>
        /// The object of the BllLesson class
        /// </summary>
        private readonly BllLesson _lesson;

        /// <summary>
        /// Construct the BllLesson class
        /// </summary>
        public BllLessonService() {
            _lesson = new BllLesson();
        }

        /// <summary>
        /// Get all the lessons
        /// </summary>
        /// <returns>The lessons</returns>
        public List<BeLesson> GetLessons() {
            try {
                return _lesson.GetLessons();
            } catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// Get all lessons in a specific week
        /// </summary>
        /// <param name="starttime">The start day</param>
        /// <param name="days">The days from the start day</param>
        /// <returns>The Lessons</returns>
        public List<BeLesson> GetEvents(DateTime starttime, int days) {
            try {
                return _lesson.GetEvents(starttime, days);
            } catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// Get a lesson from an id
        /// </summary>
        /// <param name="id">The id to get the lesson from</param>
        /// <returns>The lesson</returns>
        public BeLesson GetLesson(int id) {
            try {
                return _lesson.GetLesson(id);
            } catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// Save a lesson
        /// </summary>
        /// <param name="lesson">The lesson to save</param>
        /// <returns>A message</returns>
        public string SaveLesson(BeLesson lesson) {
            try {
                return _lesson.SaveLesson(lesson);
            } catch(Exception ex) {
                return ex.Message;
            }
        }

        /// <summary>
        /// Edit a lesson
        /// </summary>
        /// <param name="lesson">The lesson to edit</param>
        /// <returns>A message</returns>
        public string EditLesson(BeLesson lesson) {
            try {
                return _lesson.EditLesson(lesson);
            } catch(Exception ex) {
                return ex.Message;
            }
        }

        /// <summary>
        /// Edit a comment
        /// </summary>
        /// <param name="comment">The comment to edit</param>
        /// <returns>A message</returns>
        public string Editcomment(BeLesson comment) {
            try {
                return _lesson.Editcomment(comment);
            } catch(Exception ex) {
                return ex.Message;
            }
        }

        /// <summary>
        /// Delete a lesson
        /// </summary>
        /// <param name="lesson">The lesson to delete</param>
        /// <returns>A message</returns>
        public string DeleteLesson(BeLesson lesson) {
            try {
                return _lesson.DeleteLesson(lesson);
            } catch(Exception ex) {
                return ex.Message;
            }
        }

        /// <summary>
        /// Check if there is a lesson to the booking
        /// </summary>
        /// <param name="booking">The booking to check existing lesson from</param>
        /// <returns>The lesson if it is found. Null otherwise</returns>
        public BeLesson LessonPresents(BeBooking booking) {
            try {
                return _lesson.LessonPresents(booking);
            } catch(Exception ex) {
                throw new Exception(ex.Message);
            }
        }
    }
}